"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.parseToken = exports.generateToken = void 0;
const jsonwebtoken_1 = __importDefault(require("jsonwebtoken"));
const config_1 = __importDefault(require("../../config"));
const generateToken = (data) => {
    return jsonwebtoken_1.default.sign(Object.assign(Object.assign({}, data), { exp: Math.floor(Date.now() / 1000) + 60 * 60 * 24 }), config_1.default.cort);
};
exports.generateToken = generateToken;
const parseToken = (token) => {
    var _a;
    const result = {
        success: false,
        data: {}
    };
    try {
        result.success = true;
        result.data = (_a = jsonwebtoken_1.default.verify(token, config_1.default.cort)) === null || _a === void 0 ? void 0 : _a._doc;
    }
    catch (error) {
        result.success = false;
        result.data = '登录信息已过期，请重新登录';
    }
    return result;
};
exports.parseToken = parseToken;
